package cn.csq.webfilter.filter;

import cn.csq.webfilter.config.Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author csq
 * @version 1.0.0
 * @ClassName WebFilter.java
 * @Description TODO
 * @createTime 2021年12月30日 21:45:00
 */
@javax.servlet.annotation.WebFilter(urlPatterns = "/user",filterName = "webFilter")
//@Import(Config.class)
@Order(1)
@Slf4j
public class WebFilter implements Filter {


    @Autowired
    private Config config;


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("test");
        log.info("config={}",config);
        String uesrname = config.getUesrname();
        log.info("userName={}",uesrname);
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
